#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'swht'


import tornado.ioloop
import tornado.web


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        # self.write("Hello, world")
        dict = {'ID':'swht'}
        #找到template路径
        #路径 + ‘index.html’
        #open,read
        #open('index.html').read()
        #内容和字典进行渲染(替换)==>字符串
        self.render('index.html',**dict) #将字典的值传递到html中去
class HomeHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")
        # self.get_cookie() #读取cookie
        # self.set_cookie('name','swht') #设置cookie
        # self.set_secure_cookie() #加密cookie设置
class NewHandler(tornado.web.RequestHandler):
    def get(self,nid):
        self.write(str(nid))
settings = {
    'template_path' : 'template',
    'static_path':'static',
    'static_url_prefix':'/static/',
    "xsrf_cookies": True,
    # 'ui_methods': mt,
    # 'ui_modules': md,
}
application = tornado.web.Application([
    (r"/index", MainHandler),
    (r"/home", HomeHandler),
    (r"/news/(\d+)", NewHandler),
    (r"/news", HomeHandler),
],**settings) #**settings 是将环境变量加入到配置文件中


if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
